#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>

using namespace std;


struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode() : val(0), left(nullptr), right(nullptr) {}
      TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
      TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 };
 
class Solution {
public:
    void recall(TreeNode* root, string& s)
    {
        /*if (root == nullptr)
        {
            return;
        }*/
        if (root->left == nullptr && root->right == nullptr)
        {
            s += to_string(root->val);
        }
        else if (root->left != nullptr && root->right != nullptr)
        {
            s += to_string(root->val);
            s += '(';
            recall(root->left, s);
            s += ')';
            s += '(';
            recall(root->right, s);
            s += ')';
        }
        else if (root->left == nullptr && root->right != nullptr)
        {
            s += to_string(root->val);
            s += '(';
            s += ')';
            s += '(';
            recall(root->right, s);
            s += ')';
        }
        else
        {
            s += to_string(root->val);
            s += '(';
            recall(root->left, s);
            s += ')';
        }
        return;
    }
    string tree2str(TreeNode* root) 
    {
        string s;
        recall(root, s);
        return s;
    }
};

int main()
{


	return 0;
}


/*
https://leetcode.cn/problems/construct-string-from-binary-tree/description/
*/